package com.goods.controller.business;

import com.goods.business.service.OutStockService;
import com.goods.common.response.ResponseBean;
import com.goods.common.utils.JWTUtils;
import com.goods.common.vo.business.OutStockVO;
import com.goods.common.vo.system.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping("/business/outStock")
public class OutStockController {
    @Autowired
    private OutStockService outStockService;

    //出库单分页列表
    @GetMapping("/findOutStockList")
    public ResponseBean findOutStockList(@RequestParam Map<String,Object> queryMap){
       PageVO<OutStockVO> outStockVOPageVO = outStockService.findOutStockList(queryMap);
       return ResponseBean.success(outStockVOPageVO);
    }
    //出库单的明细
    @GetMapping("/detail/{id}")
    public ResponseBean detail(@PathVariable Long id, @RequestParam Integer pageNum){
        Map<Object, Object> detail = outStockService.detail(id,pageNum);
        return ResponseBean.success(detail);
    }
    //放入回收站
    @PutMapping("/remove/{id}")
    public ResponseBean remove(@PathVariable Long id){
        outStockService.remove(id);
        return ResponseBean.success();
    }
    //恢复状态
    @PutMapping("/back/{id}")
    public ResponseBean back(@PathVariable Long id){
        outStockService.back(id);
        return ResponseBean.success();
    }
    //删除出库记录
    @DeleteMapping("/delete/{id}")
    public ResponseBean delete(@PathVariable Long id){
        outStockService.delete(id);
        return ResponseBean.success();
    }
    //添加出库
    @PostMapping("/addOutStock")
    public ResponseBean addOutStock(@RequestBody OutStockVO outStockVO, HttpServletRequest request){
        String token = request.getHeader("Authorization");
        String username = JWTUtils.getUsername(token);
        outStockService.addOutStock(outStockVO,username);
        return ResponseBean.success();
    }
    //出库记录的审核
    @PutMapping("/publish/{id}")
    public ResponseBean publish(@PathVariable Long id){
        outStockService.publish(id);
        return ResponseBean.success();
    }

}
